<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-CN"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="Content-Language" content="zh-CN"><link href="stylesheet.css" media="all" rel="stylesheet" type="text/css">
<title>DROP TABLE</title>
<script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?d286c55b63a3c54a1e43d10d4c203e75"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script>
</head><body class="REFENTRY">
<div>
<table summary="Header navigation table" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><th colspan="5" align="center" valign="bottom">PostgreSQL 8.2.3 中文文档</th></tr>
<tr><td width="10%" align="left" valign="top"><a href="sql-dropsequence.html" accesskey="P">后退</a></td><td width="10%" align="left" valign="top"><a href="sql-dropsequence.html">快退</a></td><td width="60%" align="center" valign="bottom"></td><td width="10%" align="right" valign="top"><a href="sql-droptablespace.html">快进</a></td><td width="10%" align="right" valign="top"><a href="sql-droptablespace.html" accesskey="N">前进</a></td></tr>
</table>
<hr align="LEFT" width="100%"></div>
<h1><a name="SQL-DROPTABLE"></a>DROP TABLE</h1>
<div class="REFNAMEDIV"><a name="AEN51298"></a><h2>名称</h2>DROP TABLE&nbsp;--&nbsp;删除一个表</div>
<a name="AEN51301"></a>
<div class="REFSYNOPSISDIV"><a name="AEN51303"></a><h2>语法</h2>
<pre class="SYNOPSIS">DROP TABLE [ IF EXISTS ] <tt class="REPLACEABLE"><i>name</i></tt> [, ...] [ CASCADE | RESTRICT ]</pre>
</div>
<div class="REFSECT1"><a name="AEN51306"></a><h2>描述</h2>
<p><tt class="COMMAND">DROP TABLE</tt> 从数据库中删除表或视图。只有其所有者才能删除一个表或视图。要清空而不是删除表，请使用 <a href="sql-delete.html"><i>DELETE</i></a> 或 <a href="sql-truncate.html"><i>TRUNCATE</i></a> 。</p>
<p><tt class="COMMAND">DROP TABLE</tt> 总是删除目标表上现有的任何索引、规则、触发器、约束。但是，要删除一个有视图或者其它表用外键约束引用的表，必须声明 <tt class="LITERAL">CASCADE</tt> 。<tt class="LITERAL">CASCADE</tt> 将删除引用的视图，但是如果是外键约束，那么就只删除外键约束，而不是另外一个表。</p>
</div>
<div class="REFSECT1"><a name="AEN51316"></a><h2>参数</h2>
<div class="VARIABLELIST">
<dl>
<dt><tt class="LITERAL">IF EXISTS</tt></dt>
<dd><p>如果指定的表不存在，那么发出一个 notice 而不是抛出一个错误。</p></dd>
<dt><tt class="REPLACEABLE"><i>name</i></tt></dt>
<dd><p>要删除的现存表的名字(可以有模式修饰)</p></dd>
<dt><tt class="LITERAL">CASCADE</tt></dt>
<dd><p>级联删除依赖于表的对象(比如视图)</p></dd>
<dt><tt class="LITERAL">RESTRICT</tt></dt>
<dd><p>如果存在依赖对象，则拒绝删除该表。这个是缺省。</p></dd>
</dl>
</div>
</div>
<div class="REFSECT1"><a name="AEN51339"></a><h2>例子</h2>
<p>删除 <tt class="LITERAL">films</tt> 和 <tt class="LITERAL">distributors</tt> 表：</p>
<pre class="PROGRAMLISTING">DROP TABLE films, distributors;</pre>
</div>
<div class="REFSECT1"><a name="AEN51345"></a><h2>兼容性</h2>
<p>此命令兼容 SQL 标准。只不过标准只允许一条命令删除一个表。此外，<tt class="LITERAL">IF EXISTS</tt> 选项是 PostgreSQL 的扩展。</p>
</div>
<div class="REFSECT1"><a name="AEN51350"></a><h2>又见</h2><a href="sql-altertable.html"><i>ALTER TABLE</i></a>, <a href="sql-createtable.html"><i>CREATE TABLE</i></a></div>
<div>
<hr align="LEFT" width="100%">
<table summary="Footer navigation table" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td width="33%" align="left" valign="top"><a href="sql-dropsequence.html" accesskey="P">后退</a></td><td width="34%" align="center" valign="top"><a href="index.html" accesskey="H">首页</a></td><td width="33%" align="right" valign="top"><a href="sql-droptablespace.html" accesskey="N">前进</a></td></tr>
<tr><td width="33%" align="left" valign="top">DROP SEQUENCE</td><td width="34%" align="center" valign="top"><a href="sql-commands.html" accesskey="U">上一级</a></td><td width="33%" align="right" valign="top">DROP TABLESPACE</td></tr>
</table>
</div>
</body></html>